package com.pine.sunshineelder.elderheath.web.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pine.sunshineelder.common.StringHelper;
import com.pine.sunshineelder.common.dto.JSONResponse;
import com.pine.sunshineelder.common.dto.QueryResult;
import com.pine.sunshineelder.common.entity.ElderFoodEntity;
import com.pine.sunshineelder.common.entity.ElderHealthEntity;
import com.pine.sunshineelder.elderfood.vo.ElderFoodmodifyVo;
import com.pine.sunshineelder.elderheath.ao.ElderHealthAddAo;
import com.pine.sunshineelder.elderheath.service.ElderHealthService;
import com.pine.sunshineelder.elderheath.vo.ElderHealthQueryVo;
/**
 * 
 * @author 黄天静
 *
 */
@RestController
@RequestMapping("/api")
public class ElderHealthHandler implements StringHelper{
	@Autowired
	ElderHealthService elderHealthService;
	@PostMapping("/elderhealth")
	public JSONResponse addUser(ElderHealthAddAo ao) throws Exception {
		return JSONResponse.ok(elderHealthService.addElderHealth(ao));
	}
	
	
	@GetMapping("/elderhealth")
	public JSONResponse listUser(String key, String  pageNo, String pageSize) throws Exception {
		Integer pageNoUse = parseInt(pageNo, null);
		Integer pageSizeUse = parseInt(pageSize, null);
		QueryResult<ElderHealthEntity> result = elderHealthService.queryBykeyElderHealth(key, pageNoUse, pageSizeUse);
		return JSONResponse.ok(result.convert(ElderHealthQueryVo::of));
	}
	
	@GetMapping("/elderhealth/{id}")
	public JSONResponse listUser(@PathVariable String id) throws Exception {
		ElderHealthEntity queryById = elderHealthService.queryByIdElderHealth(id);
		return JSONResponse.ok(queryById);
	}
	
}
